﻿#ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H

#include <QMainWindow>
#include <QTextCursor>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class QDialog;
class QLabel;
class QLineEdit;

class MainWindow : public QMainWindow {
  Q_OBJECT

 public:
  MainWindow(QWidget* parent = nullptr);
  ~MainWindow();

 private slots:
  void on_action_New_triggered();
  void on_action_Save_triggered();
  void on_action_SaveAs_triggered();
  void on_action_Open_triggered();
  void on_action_Close_triggered();
  void on_action_Exit_triggered();
  void on_action_Undo_triggered();
  void on_action_Cut_triggered();
  void on_action_Copy_triggered();
  void on_action_Paster_triggered();
  void on_action_Find_triggered();
  void ShowFindText();

 protected:
  void closeEvent(QCloseEvent* event);  // 关闭事件

 private:
  void NewFile();
  bool MaybeSave();
  bool Save();
  bool SaveAs();
  bool SaveFile(const QString& file_name);
  bool LoadFile(const QString& fileName);

  void move(QString str);

  Ui::MainWindow* ui;
  QLineEdit* find_lineedit_;
  QDialog* find_dialog_;
  QTextCursor highlight_cursor_;
  QLabel* statusLabel;

  // 为真表示当前文件被保存过了
  bool is_untitled = true;
  QString current_file;
};
#endif  // MAIN_WINDOW_H
